


def update_probability(PO: int, P_Z_given_O: float, P_Z_given_not_O: float) -> int:
    # 计算 P_O
    P_O = PO / 256.0

    # 计算 P_Z
    P_Z = P_Z_given_O * P_O + P_Z_given_not_O * (1.0 - P_O)

    # 计算 P_O_given_Z
    P_O_given_Z = (P_Z_given_O * P_O) / P_Z

    # 映射回 0-255 范围
    ans = int(P_O_given_Z * 256)

    # 限制最大值为 255
    return min(ans, 255), P_O_given_Z


if __name__ == "__main__":


    prob = 0.7
    p1 = 0.49
    p2 = 1 - p1
    porb_value = int(prob * 255)
    print("*"*10)
    for i in range(10):
        ans, score = update_probability(porb_value, p1, p2)
        print(ans, f"{score:.3f}")

        porb_value = ans
